/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gr.anagnosg.image.imagemagick;

import java.util.ArrayList;
import java.util.List;
import org.im4java.core.IMOperation;

/**
 *
 * @author anagnosg
 */
public class Param {
    List<ParamElement> elList = new ArrayList<ParamElement>();
    int paramLength = 0 ; 
    String  type = null;//resize ktl from constants. 
    int paramCase = 0;
    String filenameSource ;
    String filenameDest ; 
    int finishStatus = 0 ; 
    String value = "";
    String action ="";

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getParamOption() {
        return paramOption;
    }

    public void setParamOption(String paramOption) {
        this.paramOption = paramOption;
    }
    String paramOption ="";
    
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
    

    public int getFinishStatus() {
        return finishStatus;
    }

    public void setFinishStatus(int finishStatus) {
        this.finishStatus = finishStatus;
    }
    
    
    
    
    public List<ParamElement> getElList() {
        return elList;
    }

    public void setElList(List<ParamElement> elList) {
        this.elList = elList;
    }

    public int getParamLength() {
        return paramLength;
    }

    public void setParamLength(int paramLength) {
        this.paramLength = paramLength;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
 
    public int getExecLength(){
        int output = 0 ; 
        for(int i = 0 ; i < this.elList.size(); i ++){
            ParamElement paramEl = elList.get(i);
            if(!paramEl.isDisplayOnly()){output++;}
        }
        return output;
    }
    
    
    public ParamElement getExecElement(int orderOfParam){
        int execOrder = 0 ;
        ParamElement output = null;
        for(int i = 0 ; i < this.elList.size(); i++){
            ParamElement parEl = this.elList.get(i);
            if(!parEl.isDisplayOnly()){execOrder++;}
            if (orderOfParam==execOrder){output=parEl;break;}
            
        }
        return output;
    }
    public IMOperation createExecuteObj(){
        IMOperation imoper = new IMOperation();
        int lengthOfExec = this.getExecLength();
        String actionStr = this.getType();
        imoper.addImage(this.filenameSource);
        if(actionStr.equals(Constants.RESIZE_STR)){
        
            imoper.resize();
            if(lengthOfExec==1){
                imoper.resize(Integer.parseInt(this.getExecElement(0).getValue()));
            }
            else if(lengthOfExec==2){
                imoper.resize(Integer.parseInt(this.getExecElement(0).getValue()), Integer.parseInt(this.getExecElement(1).getValue()));
            }
            else if(lengthOfExec==3 &&  this.getExecElement(3).getValue().length()==1){
                    imoper.resize(Integer.parseInt(this.getExecElement(0).getValue()), Integer.parseInt(this.getExecElement(1).getValue()),this.getExecElement(3).getValue().charAt(0));
            }
            else if(lengthOfExec==3 &&  this.getExecElement(3).getValue().length()>1){
                    imoper.resize(Integer.parseInt(this.getExecElement(0).getValue()), Integer.parseInt(this.getExecElement(1).getValue()),this.getExecElement(3).getValue());
            }
        }
        imoper.addImage(this.filenameDest);
        return imoper;
    }
    
    
    public String convert2String(){
    
        String output="-"+this.type +" ";
        for(int i = 0 ; i < this.elList.size();i++){
            output+=this.elList.get(i).getValue();
        }
        return output;
    }
    
    
}
